<!--
    说明：招聘企业-企业预览pc
 -->
<template>
  <section class="pc-review-page">
    <!-- 公司基本信息  -->
    <div class="company-info">
      <img
        v-if="companyInfo.companyLogo"
        v-imgError
        class="logo-img"
        :src="companyInfo.companyLogo"
        alt="logo"
      >
      <img
        v-else
        v-imgError
        class="logo-img"
        src="../../../assets/images/logo_demo.png"
        alt="logo"
      >
      <div class="right-block">
        <div class="name">{{ companyInfo.companyName }}</div>
        <div v-if="companyInfo.industry" class="area">{{ companyInfo.industry[companyInfo.industry.length - 1] }}</div>
      </div>
      <div class="right-hire">
        <div class="hire-num">{{ companyInfo.recruitmentCount || 0 }}</div>
        <div class="hire-title">在招职位</div>
        <div class="click-num">点击量：{{ companyInfo.clickCount || 0 }}</div>
      </div>
      <div class="tag">
        <span
          :class="['item', { current: tagType === 0 }]"
          @click="tagType = 0"
        >企业介绍</span>
        <span
          :class="['item', { current: tagType === 1 }]"
          @click="tagType = 1"
        >在招职位</span>
      </div>
    </div>
    <section v-show="tagType === 0">
      <!-- 热招职位 -->
      <div class="row-item">
        <div class="title">
          热招职位
          <div class="all" @click="tagType = 1">
            <span class="all-icon" />查看全部职位
          </div>
        </div>
        <el-empty description="暂无数据" />
      </div>
      <!-- 企业简介 -->
      <div class="row-item">
        <div class="title">{{ companyInfo.companyName }}简介</div>
        <div
          v-if="companyInfo.introduction"
          class="company-desc"
          v-html="companyInfo.introduction.replace(/\n/gm, '<br>')"
        />
        <el-empty v-else description="暂无数据" />
      </div>
      <!-- 企业环境 -->
      <div class="row-item">
        <div class="title">企业环境</div>
        <div
          v-if="Array.isArray(imgVideoList) && imgVideoList.length"
          id="mySwiper"
          class="company-environment swiper"
        >
          <div class="swiper-wrapper">
            <div
              v-for="(item, index) in imgVideoList"
              :key="index"
              class="swiper-slide"
            >
              <div style="width: 500px; height: 280px">
                <el-image
                  v-if="item.type == 'img'"
                  :src="item.url"
                  alt=""
                  :preview-src-list="imgList.src"
                  fit="cover"
                  style="width: 500px; height: 280px"
                />
                <vueVideoPlayer
                  v-else
                  :ref="`video${index}`"
                  :src="item.url"
                  :autoplay="false"
                  @onPlay="videoPlay(index)"
                />
                <div
                  v-if="item.updateTime"
                  style="text-align: right; font-size: 12px; color: #9597a0; margin-bottom: 20px;"
                >
                  更新时间：{{ item.updateTime }}
                </div>
              </div>
            </div>
          </div>
          <div class="swiper-button-prev" @click.stop="slidePrev" />
          <div class="swiper-button-next" @click.stop="slideNext" />
        </div>
        <el-empty v-else description="暂无数据" />
      </div>
      <!-- 企业地址 -->
      <div class="row-item">
        <div class="title">企业地址</div>
        <div
          v-if="
            companyInfo.companyAddress &&
              companyInfo.companyAddress.length > 0
          "
          class="company-address"
        >
          <div
            v-for="(item, index) in companyInfo.companyAddress"
            :key="index"
            class="item"
          >
            <span class="position-icon" />
            {{ item.province !== item.city ? item.province : '' }}
            {{ item.city }}
            {{ item.address }}
          </div>
        </div>
        <el-empty v-else description="暂无数据" />
      </div>
    </section>
    <section v-show="tagType === 1">
      <!-- 搜索工作栏 -->
      <el-form
        ref="queryForm"
        style="margin: 22px 0 0"
        :model="queryParams"
        :inline="true"
        label-width="68px"
      >
        <el-form-item prop="status">
          <i class="condition-icon" />
          <el-cascader
            v-model="queryParams.city"
            size="mini"
            :show-all-levels="false"
            :options="provinceAndCityData"
            :props="{ value: 'label' }"
            placeholder="工作城市"
          />
        </el-form-item>
        <el-form-item prop="companyName">
          <el-select
            v-model="queryParams.studentType"
            size="mini"
            placeholder="招聘对象"
            clearable
          >
            <el-option
              v-for="dict in studentType"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item prop="status">
          <el-select
            v-model="queryParams.education"
            size="mini"
            placeholder="学历要求"
            clearable
          >
            <el-option
              v-for="dict in educationOptions"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            size="mini"
            type="danger"
            @click="resetQuery"
          >重置</el-button>
          <el-button
            size="mini"
            type="primary"
            @click="handleQuery"
          >搜索</el-button>
        </el-form-item>
      </el-form>
      <section class="job-list">
        <el-empty
          description="暂无相关职位"
        />
      </section>
    </section>
  </section>
</template>

<script>
import Swiper from 'swiper'
import 'swiper/swiper.scss'
import {
  provinceAndCityData,
  studentType,
  educationOptions,
  getEducationName
} from '@/utils/frontDataDict.js'
import vueVideoPlayer from '../../../components/videoPlayer'
export default {
  name: 'PcReview',
  components: {
    vueVideoPlayer
  },
  data() {
    return {
      provinceAndCityData,
      studentType,
      educationOptions,
      total: 0,
      tagType: 0,
      swiper: null,
      companyInfo: {},
      jobList: [],
      shortJobList: [],
      imgList: [],
      imgVideoList: [],
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        nickname: null,
        phoneNumber: null,
        companyName: null,
        authorizedStatus: null,
        status: null,
        accountType: '' // 账号类型
      }
    }
  },
  watch: {
    tagType(newValue, oldValue) {
      if (newValue !== oldValue && newValue === 1) {
        this.stopVideo()
      }
    }
  },
  mounted() {
    this.initSwiper()
  },
  methods: {
    resetQuery() {
    },
    handleQuery() {
    },
    stopVideo() {
      this.imgVideoList.map((item, inx) => {
        if (item.type === 'video') {
          this.$refs[`video${inx}`][0].pause()
        }
      })
    },
    videoPlay(index) {
      const videoItem = this.$refs[`video${index}`][0]
      videoItem &&
        this.imgVideoList.map((item, inx) => {
          if (item.type === 'video' && inx !== index) {
            this.$refs[`video${inx}`][0].pause()
          }
        })
    },
    init(companyInfo) {
      const data = JSON.parse(JSON.stringify(companyInfo))
      if (data) {
        try {
          if (Array.isArray(JSON.parse(data.industry))) {
            data.industry = JSON.parse(data.industry)[1]
          }
          if (Array.isArray(JSON.parse(data.companyAddress))) {
            data.companyAddress = JSON.parse(data.companyAddress)
          }
          data.education = getEducationName(data.education)
        } catch {
          () => {}
        }
        try {
          this.imgVideoList = []
          data.environment = JSON.parse(data.environment)
          data.environment.videoList.forEach((v) => {
            console.log(v)
            v.src && this.imgVideoList.push({
              type: 'video',
              url: v?.src ?? v,
              updateTime: v?.updateTime ?? ''
            })
          })
          data.environment.imgList.forEach((v) => {
            this.imgVideoList.push({
              type: 'img',
              url: v?.src ?? v,
              updateTime: v?.updateTime ?? ''
            })
          })
        } catch {
          () => {}
        }
        this.companyInfo = data
        this.imgList = data.environment.imgList
        setTimeout(() => {
          this.initSwiper()
        })
      }
    },
    initSwiper() {
      if (this.swiper === null) {
        this.swiper = new Swiper('#mySwiper', {
          slidesPerView: 'auto',
          spaceBetween: 25,
          observer: true,
          observeParents: true,
          navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev'
          }
        })
      }
    },
    slidePrev() {
      this.swiper.slidePrev()
    },
    slideNext() {
      this.swiper.slideNext()
    }
  }
}
</script>
<style lang="scss" scoped>
.el-image__error,
.el-image__inner,
.el-image__placeholder {
  padding-top: 66.66%;
}
.pc-review-page {
  position: relative;
  padding: 40px;
  background: #fff;
  .company-info {
    position: relative;
    height: 212px;
    width: 100%;
    border-bottom: 1px solid #d4d6da;
    padding-bottom: 42px;
    .logo-img {
      display: block;
      width: 100px;
      height: 100px;
      background: #ffffff;
      border-radius: 8px;
      border: 1px solid #d4d6da;
      float: left;
      margin-right: 30px;
    }
    .right-block {
      position: relative;
      overflow: hidden;
      width: calc(100% - 130px);
      height: 100px;
      display: flex;
      flex-flow: column nowrap;
      justify-content: center;
      align-items: flex-start;
      .name {
        font-size: 35px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #37383d;
        line-height: 40px;
        margin-bottom: 12px;
      }
      .area {
        font-size: 22px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #9597a0;
        line-height: 30px;
      }
    }
    .right-hire {
      position: absolute;
      top: 0;
      right: 0;
      width: 40%;
      height: 100%;
      padding-top: 8px;
      display: flex;
      flex-flow: column nowrap;
      justify-content: flex-start;
      align-items: flex-end;
      .hire-num {
        font-size: 32px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #37383d;
        line-height: 40px;
        margin-bottom: 6px;
        // padding-right: 15px;
      }
      .hire-title {
        font-size: 16px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #9597a0;
        line-height: 22px;
        margin-bottom: 15px;
      }
      .btn {
        width: 146px;
        height: 44px;
        line-height: 44px;
        font-size: 18px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #ffffff;
        background: #3d6cb0;
        text-align: center;
        border-radius: 34px;
        cursor: pointer;
        margin-bottom: 13px;
        .edit-icon {
          display: inline-block;
          width: 14px;
          height: 16px;
          background: url("../../../assets/images/edit-icon.png") no-repeat center
            center / cover;
        }
        &:hover {
          color: #2f8efe;
        }
      }
      .click-num {
        font-size: 15px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #9597a0;
        line-height: 22px;
        // padding-right: 4px;
      }
    }
    .tag {
      position: absolute;
      left: 0;
      bottom: 8px;
      width: 50%;
      height: 30px;
      padding-left: 10px;
      .item {
        font-size: 18px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #9597a0;
        line-height: 24px;
        margin-right: 25px;
        vertical-align: bottom;
        cursor: pointer;
      }
      .item:hover {
        color: #2f8efe;
      }
      .current {
        font-size: 22px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #2f8efe;
        line-height: 24px;
      }
    }
  }
  .row-item {
    position: relative;
    width: 100%;
    padding: 15px 0 15px;
    border-bottom: 1px solid #d4d6da;
    overflow-x: hidden;
    &:last-child {
      border-bottom: 1px solid #fff;
    }
    .title {
      position: relative;
      text-align: left;
      font-size: 22px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #37383d;
      line-height: 40px;
      margin-bottom: 15px;
      .all {
        position: absolute;
        right: 0;
        bottom: 0;
        font-size: 18px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #2f8efe;
        line-height: 40px;
        vertical-align: middle;
        cursor: pointer;
        .all-icon {
          display: inline-block;
          width: 20px;
          height: 20px;
          background: url("../../../assets/images/check_all.png") no-repeat center
            center / cover;
          vertical-align: middle;
          margin-right: 10px;
        }
      }
    }
    .job-item {
      position: relative;
      background: #ffffff;
      border-radius: 10px;
      border: 1px solid #d4d6da;
      padding: 15px;
      cursor: pointer;
      .row1 {
        position: relative;
        display: flex;
        flex-flow: row nowrap;
        justify-content: space-between;
        margin-bottom: 15px;
        .job-name {
          font-size: 18px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #37383d;
          line-height: 24px;
          margin-bottom: 10px;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
        }
        .salary {
          width: 140px;
          font-size: 16px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #9597a0;
          line-height: 24px;
          text-align: right;
        }
      }
      .other {
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #9597a0;
        line-height: 20px;
        .line {
          position: relative;
          display: inline-block;
          width: 1px;
          height: 14px;
          background: #9597a0;
          margin: 0 8px;
        }
      }
      &:hover {
        box-shadow: 0px 4px 15px 0px rgba(0, 0, 0, 0.08);
        .job-name {
          color: #2f8efe;
        }
      }
    }
    .company-desc {
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #9597a0;
      line-height: 27px;
      word-break: break-all;
    }
    .company-environment {
      width: 100%;
      height: 100%;
      position: relative;
      .swiper-slide {
        width: 500px;
        height: 300px;
        text-align: center;
        font-size: 16px;
        background: #fff;
        display: flex;
        justify-content: flex-start;
        align-items: flex-start;
        overflow: hidden;
      }
      .swiper-slide img {
        display: block;
        width: 100%;
        object-fit: cover;
        padding-top: 66.66% !important;
      }
      .swiper-slide .video {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
      .swiper-button-next {
        position: absolute;
        right: -50px;
        top: 50%;
        margin: 0;
        transform: translateY(-50%) scale(.8);
        width: 180px;
        height: 180px;
        background: url(../../../assets/images/next.png) no-repeat;
        background-position: center;
        background-size: cover;
        cursor: pointer;
        z-index: 5;
        &::after{
          display: none;
        }
      }
      .swiper-button-prev {
        position: absolute;
        left: -50px;
        top: 50%;
        margin: 0;
        transform: translateY(-50%) scale(.8);
        width: 180px;
        height: 180px;
        background: url(../../../assets/images/prev.png) no-repeat;
        background-position: center;
        background-size: cover;
        cursor: pointer;
        z-index: 5;
        &::after{
          display: none;
        }
      }
    }
    .company-address {
      position: relative;
      .item {
        font-size: 18px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #37383d;
        margin-top: 35px;
        line-height: 24px;
        cursor: pointer;
        &:first-child {
          margin-top: 0;
        }
        .position-icon {
          display: inline-block;
          width: 15px;
          height: 20px;
          margin-right: 10px;
          background: url("../../../assets/images/position.png") no-repeat center
            center / cover;
          vertical-align: middle;
        }
      }
    }
  }
  .condition-icon {
    display: inline-block;
    width: 24px;
    height: 24px;
    background: url("../../../assets/images/condition.png") no-repeat center center /
      cover;
    vertical-align: middle;
    margin-right: 10px;
  }
  .job-list {
    position: relative;
    .item {
      position: relative;
      width: 100%;
      margin-bottom: 15px;
      border-radius: 10px;
      padding: 25px 0 36px 25px;
      border: 1px solid #d4d6da;
      overflow: hidden;
      &::before {
        content: "";
        display: block;
        width: 10px;
        height: 100%;
        background: #4677b9;
        position: absolute;
        top: 0;
        left: 0;
      }
      .job-name {
        font-size: 22px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #37383d;
        line-height: 36px;
        margin-bottom: 15px;
        .city {
          font-size: 20px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #9597a0;
          line-height: 30px;
          vertical-align: bottom;
          margin-left: 15px;
        }
      }
      .other {
        font-size: 18px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #9597a0;
        line-height: 30px;
        .line {
          position: relative;
          display: inline-block;
          width: 1px;
          height: 14px;
          background: #9597a0;
          margin: 0 10px;
        }
      }
      .btn {
        position: absolute;
        width: 122px;
        height: 42px;
        line-height: 42px;
        background: #4677b9;
        border-radius: 4px;
        right: 30px;
        top: 50%;
        margin-top: -20px;
        text-align: center;
        font-size: 17px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #ffffff;
        cursor: pointer;
      }
      &:hover {
        box-shadow: 0px 4px 15px 0px rgba(0, 0, 0, 0.08);
        .job-name {
          color: #2f8efe;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
